package com.groupsix.controller;

import com.groupsix.entity.Dormgrade;
import com.groupsix.service.DormgradeService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 宿舍卫生控制器
 * @date 2021/10/17 22:09
 */
@Controller
public class DormgradeController {
    //依赖注入
    @Autowired
    private DormgradeService dormgradeService;

    /**
     * 分页查询
     * pageIndex 当前页码
     * pageSize  显示条数
     */
    @RequestMapping("/findDormgrade.action")
    public String findDormClean(Integer dId,String dDormbuilding,
                                Integer pageIndex, Integer pageSize, Model model) {

        PageInfo di = dormgradeService.findPageInfo(dId,dDormbuilding,
                pageIndex,pageSize);
        model.addAttribute("di",di);
        return "dormgrade_list";
    }


    /**
     * 添加宿舍卫生信息
     */
    @RequestMapping(value = "/addDormgrade.action" ,method = RequestMethod.POST)
    @ResponseBody
    public String addDormClean( @RequestBody Dormgrade dormgrade) {
        int d = dormgradeService.addDormgrade(dormgrade);
        return "dormgrade_list";
    }

    /**
     * 删除宿舍卫生信息
     */
    @RequestMapping( "/deleteDormgrade.action")
    @ResponseBody
    public String deleteDormClean(Integer gId) {
        int d = dormgradeService.deleteDormgrade(gId);
        return "dormgrade_list";
    }

    /**
     * 修改宿舍卫生信息
     */
    @RequestMapping( "/updateDormgrade.action")
    public String updateDormClean( Dormgrade dormgrade) {
        int d = dormgradeService.updateDormgrade(dormgrade);
        return "redirect:/findDormgrade.action";
    }


    @RequestMapping( "/findDormgradeById.action")
    public String findDormCleanById(Integer gId, HttpSession session) {

        Dormgrade d= dormgradeService.findDormgradeById(gId);
        session.setAttribute("d",d);
        return "dormclean_edit";
    }
}
